<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/jsp/common/common.jsp" %>
</head>
<body>

<div class="documentContent"  id="documentContent">
	<div class="top-div"><em></em><span>&nbsp;>&nbsp;系统监控&nbsp;>&nbsp;概要信息</span></div>
	
		<div>
	    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="search-table">
	      <tr>
	        <td style="float: right;">
		        <button class="btn-table" id="draftButton">起草</button>
		        <button class="btn-table" id="submitButton">提交</button>
		        <button class="btn-table" id="refreshButton">刷新数据</button>
	        </td>
	      </tr>
	    </table>
	  </div>
	
	<!-- form-box -->
	<div class="form-box">
		<h2 class="form-title">流程实例<em class="show"></em></h2>
		<div class="form-content">
		 	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="form-table">
		 		<tr>
		 			<td class="form-table-tdleft" width="25%">流程状态</td>
		 			<td width="25%"><span id="processState_span"></span></td>
		 			<td class="form-table-tdleft" width="25%">创建时间</td>
		 			<td width="25%"><span id="createTimeStr_span"></span></td>
		 		</tr>
		 		<tr>
		 			<td class="form-table-tdleft" width="25%">创建人</td>
		 			<td width="25%"><span id="createUserName_span"></span></td>
		 			<td class="form-table-tdleft" width="25%">完成时间</td>
		 			<td width="25%"><span id="finishTimeStr_span"></span></td>
		 		</tr>
		 	</table>
		</div>
	</div>
	<!-- form-box -->
	
	<!-- form-box -->
	<div class="form-box">
		<h2 class="form-title">任务信息<em class="show"></em></h2>
		<div class="form-content">
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="form-subtable">
				<thead>
					<tr>
						<th width="10%">任务状态</th>
						<th width="50%">创建时间</th>
						<th width="20%">执行人</th>
						<th width="20%">环节名称</th>
					</tr>
				</thead>
				<tbody id="gcTbody"></tbody>
			</table>
		</div>
	</div>
	<!-- form-box -->
	

	
	  <input type="text" name="processInstanceId" id="processInstanceId" value="" />
</div>

<script type="text/javascript">
$(document).ready(function(){

	blindPageElement();
	
});

function blindPageElement(){
	$(".form-title").click(function(){
        var b = $(this).parent(".form-box").children(".form-content");
        if(b.css("display") == "block"){
			b.slideUp();
            $(this).children("em").removeClass("show");
            $(this).children("em").addClass("hide");
        }else{
            $(this).children("em").removeClass("hide");
            $(this).children("em").addClass("show");
			b.slideDown();
        }
    });
	
	$('#draftButton').on('click',function(){
	 	var url = '<%=basePath%>/biz/workflow/sampleDocument/draftProcess.do?processDefinitionId=PD-001';
		$.ajax({  
	        url:url,  
	        type:'post',  
	        dataType:'json',  
	        success:function(data,textStatus,jqXHR){  
	        	$('#processInstanceId').val(data.processInstanceId);
	        	alert('起草成功');
	        },  
	        error:function(XMLHttpRequest,textStatus,errorThrown){  
	        	alert('起草失败');
	        }                     
	    });
	});
	
	$('#submitButton').on('click',function(){
	 	var url = '<%=basePath%>/biz/workflow/sampleDocument/submitProcess.do?processInstanceId='+$('#processInstanceId').val();
		$.ajax({  
	        url:url,  
	        type:'post',  
	        dataType:'json',  
	        success:function(data,textStatus,jqXHR){  
	        	alert('提交成功');
	        },  
	        error:function(XMLHttpRequest,textStatus,errorThrown){  
	        	alert('提交失败');
	        }                     
	    });
	});
	
	$('#refreshButton').on('click',function(){
	 	var url = '<%=basePath%>/biz/workflow/sampleDocument/getProcessData.do?processInstanceId='+$('#processInstanceId').val();
		$.ajax({  
	        url:url,  
	        type:'post',  
	        dataType:'json',  
	        success:function(data,textStatus,jqXHR){  
	        	
	 			var processInstance = data.processInstance;
	        	$.each(processInstance,function(key,value){
	        		if($('#'+key+'_span')){
	        			$('#'+key+'_span').html(value);
	        		}
	        	});
	        	
	        	writeGcTbody(data.taskList);
	        	
	        },  
	        error:function(XMLHttpRequest,textStatus,errorThrown){  
	        	alert('刷新失败');
	        }                     
	    });
	});
}


function writeGcTbody(data){
	var gcTbody = $('#gcTbody');
	$(gcTbody).empty();
	
	$(data).each(function(index,element){
		
		var trObj = $('<tr></tr>');
		
		$(trObj).append('<td>'+element.taskState+'</td>');
		$(trObj).append('<td>'+element.createTimeStr+'</td>');
		$(trObj).append('<td>'+element.executeName+'</td>');
		$(trObj).append('<td>'+element.activityName+'</td>');
		
		
		$(gcTbody).append(trObj);
	});
}



</script>
</body>
</html>